

function formInitFunc(){
	var thTaskDefid = "obj_c7444af5586000012a4915f01047ae10";
	if(thTaskDefid == userTaskDefId){
		$("#RECORDTYPETR").show();
	}else{
		$("#RECORDTYPETR").hide();
	}
	
}



/**
*打开rowData1
*/
function openData1(rowData1,rowData2){
	
		rowData1.style.position="inherit";
		rowData1.style.visibility="";

		zwdiv.style.height="0px";
		rowData2.style.height="0px";
		rowData2.style.visibility="hidden";

		Tab1.className="tab1";
		Tab2.className="tab2";
}
/**
*打开rowData2
*/
function openData2(rowData1,rowData2){
  
	

	rowData2.style.height="0px";
	zwdiv.style.height="0px";
	
	//Tab1.className="tab2";
	//Tab2.className="tab1";
	try{
		WebOffice.FullSize(true);
	}catch(e){}
	
	loadGRCFile();
	
	
    
}


function loadGRCFile(){
	if(WebOffice.FilePath == null || WebOffice.FilePath == 'null' || WebOffice.FilePath == 'undefined'){
		var downloadUrl = getFileDCDownLoadPathStr("BO_WHBK_OD_INSTITUTION","ATTFILE",bindid);
		debugger;
	    var fileName = $("input[name=DOC_NAME]").val();
	    var currFilePath;
	    if(WebOffice.WebAcceptAllRevisions()){//清除正文痕迹的目的是为了避免痕迹状态下出现内容异常问题。
	       currFilePath = WebOffice.getFilePath(); //获取2015特殊路径
	       //WebOffice.WebSaveLocalFile(currFilePath+processInstId+WebOffice.iWebOfficeTempName);//将当前文档保存下来
	       if(WebOffice.DownloadToFile(downloadUrl,fileName,currFilePath)){//下载服务器指定的文件
	          WebOffice.OpenLocalFile(currFilePath+fileName);//打开该文件
	          WebOffice.obj.ActiveDocument.saved=false;
			  //WebOffice.WebSave();//保存文件
	          return; 
	       }
	       return;
	    }
	}
	//WebOffice.FullSize(true);
	
}


function getFileDCDownLoadPathStr(boName,fieldName,bindid){
	var downloadUrl = "";
	awsui.ajax.request({
		url : "./jd",
		method : "POST",
		async : false,// 同步
		data : {sid:sid, 
				boName:boName,
				fieldName:fieldName,
				bindid:bindid,
				cmd:"com.whccb.apps.business.pub_getFileDCDownLoadPathStr"
				},
				ok : function(r) {
					if(r != null && r != 'undefined'){
						downloadUrl = r.data.downloadUrl;
					}

				},
				err:function(r){
								alert(r)    
				}
	});
	return downloadUrl;
}


function btclickBefore(buttonName){
	if("公文套红" == buttonName){
		var NUM = $("input[name=NUM]").val();
		if(NUM == null || NUM == '' || NUM == 0 || NUM == '0' || NUM == 'undefined' ){
			$.simpleAlert("请先通过<申请文号>按钮确定文号", "error");
			return false;
		}
	}
	if("申请文号" == buttonName){
		var NUM = $("input[name=NUM]").val();
		if(NUM != null && NUM != '' && NUM != 0 && NUM != '0' && NUM != 'undefined' ){
			$.simpleAlert("当前发文已有文号，如需修改，请通过<修改文号>按钮来完成", "error");
			return false;
		}
		var RECORDTYPE = $("input[name=RECORDTYPE]").val();
		if(RECORDTYPE == null || RECORDTYPE == '' || RECORDTYPE == 'undefined' ){
			$.simpleAlert("请先通过<选择文种>按钮确定文种", "error");
			return false;
		}
	}
	if("修改文号" == buttonName){
		var NUM = $("input[name=NUM]").val();
		if(NUM == null || NUM == '' || NUM == 0 || NUM == '0' || NUM == 'undefined' ){
			$.simpleAlert("请先通过<申请文号>按钮确定文号", "error");
			return false;
		}
		$("input[name=oldFileNum]").val(NUM);
		showModifyFileNumDlg();
	}
	
	if("选择文种" == buttonName){
		var RECORDTYPE = $("input[name=RECORDTYPE]").val();
		if(RECORDTYPE != null && RECORDTYPE != '' && RECORDTYPE != 'undefined' ){
			$.simpleAlert("文种一经确定,即不能修改。", "error");
			return false;
		}else{
			if(!confirm("文种一经确定,即不能修改,请确认!")){
				return false;
			}else{

			}
		}
	}
}




function showModifyFileNumDlg() {
    
    var recordTypeId = $("input[name=RECORDTYPEID]").val(); 	
	var year = $("input[name=YEAR]").val(); 	
	$("#modifyFileNumDlg").dialog({
		"buttons":[{text:'确定',cls:"red",handler:function(){
							var newFileNum = $("input[name=newFileNum]").val();
							//非空校验
							if (newFileNum == "") {
								$.simpleAlert("[拟使用文号]不允许为空","info");
								return;
							}
							awsui.ajax.request({
							    url : "./jd",
							    method : "POST",
							    data : {sid:sid, 
							    		bindid:bindid,
							    		boName:"BO_WHBK_OD_INSTITUTION",
										recordTypeId:recordTypeId,
										year:year,
										flag:"0",//发文
										fileNum:newFileNum,
										cmd:"com.whccb.apps.office.document.modify_file_num"
							    	   },
							    ok : function(r) {
									debugger;
									var fileNum = r.data.fileNum;
									var odFileNum = r.data.odFileNum;
		                            $("input[name=FILENUM]").val(odFileNum);
									$("input[name=NUM]").val(fileNum);
		                            $("#NUM_Readonly").html(fileNum);
									alert("新文号更新成功");
									$("#modifyFileNumDlg").dialog("close");
							    },
							    err:function(r){
									debugger;
							    }
							});
							
						}},
						{text:'取消',handler:function(){
							$("#modifyFileNumDlg").dialog("close");
						}}]
	});
}






function btclickSuccess(buttonName,response){
	if("申请文号" == buttonName){
		var fileNum = response.data.fileNum;
		var odFileNum = response.data.odFileNum;
		$("input[name=FILENUM]").val(odFileNum);
		$("input[name=NUM]").val(fileNum);
		$("#NUM_Readonly").html(fileNum);
		alert("文号申请成功，为"+fileNum+"号");
	}
}

function btclickFailure(buttonName,response){
	if("申请文号" == buttonName){
		alert("参数有误，BO未找到");
	}
}

function selectType(typeId,typeName){
	//ajax调用保存文种
	
	awsui.ajax.request({
		url : "./jd",
		method : "POST",
		data : {
					sid:sid, 
					bindid:bindid,
					boName:"BO_WHBK_OD_INSTITUTION",
					recordTypeId:typeId,
					recordTypeName:typeName,
					cmd:"com.whccb.apps.office.document.modify_file_type"
				},
		ok : function(r) {
					debugger;
					var recordTypeId = r.data.recordTypeId;
					var recordTypeName = r.data.recordTypeName;
					$("input[name=RECORDTYPEID]").val(recordTypeId);
	                $("input[name=RECORDTYPE]").val(recordTypeName);
	                $("#RECORDTYPE_Readonly").html(recordTypeName);
				},
		 err:function(r){
				    debugger;
				}
		});
	
	
}
